package com.cloud.check.api.provider;

import com.cloud.check.api.bean.RecCheckCriteriaBean;
import com.cloud.check.common.utils.DateHelper;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.SQL;

public class CheckPageProvider {
    private static final String LIST_PAGE_SELECT = "t1.rec_id, t1.task_num, t1.check_mode, t1.check_form, t1.supervise_item_implement, t1.check_date, t1.check_type",
                                LIST_PAGE_FOMR = "rec_check t1";

    public String listPage(RecCheckCriteriaBean bean) {
        SQL sql = new SQL().SELECT(LIST_PAGE_SELECT).FROM(LIST_PAGE_FOMR);

        if(!StringUtils.isEmpty(bean.getTaskNum())) {
            sql.WHERE(" t1.task_num = '" + bean.getTaskNum() + "' ");
        }

        if(!StringUtils.isEmpty(bean.getCheckMode())) {
            sql.WHERE(" t1.check_mode = '" + bean.getCheckMode() + "' ");
        }

        if(!StringUtils.isEmpty(bean.getCheckForm())) {
            sql.WHERE(" t1.check_form = '" + bean.getCheckForm() + "' ");
        }

        if(!StringUtils.isEmpty(bean.getSuperviseItemImplement())) {
            sql.WHERE(" t1.supervise_item_implement like '%" + bean.getSuperviseItemImplement() + "%' ");
        }

        if(bean.getCheckDate() != null) {
            sql.WHERE(" t1.check_date = "  + DateHelper.strToDateSql(DateHelper.dateToStr(bean.getCheckDate()),
                    0, DateHelper.DB_TYPE_MYSQL));
        }

        if(!StringUtils.isEmpty(bean.getCheckType())) {
            sql.WHERE(" t1.check_type = '" + bean.getCheckType() + "' ");
        }

        if(bean.getUnitId() != null) {
            sql.WHERE(" t1.law_subject_id = '" + bean.getUnitId() + "' ");
        }

        sql.WHERE(" delete_flag != 1");
        System.out.println(sql.toString());
        return sql.toString();
    }
}
